package cn.edu.hizee.gps.util;

import cn.edu.hizee.gps.model.JsonTf;
import cn.edu.hizee.gps.model.PushInfo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * @author ZX
 */
public class MulitUtil {

    private static String oid = "9943";
    private static String key = "9838x19vv8x47505857v5w7y04u4w3244zy06";

    public PushInfo analysis(String requestMsg){
        System.out.println("requestMsg" + requestMsg);
        String strings[] = requestMsg.replace(" ZGPSR: ","").split(",");
        String lng = String.valueOf(Double.valueOf(strings[1].substring(0,3)) + Double.valueOf(strings[1].substring(3))/60);
        String lat = String.valueOf(Double.valueOf(strings[0].substring(0,2)) + Double.valueOf(strings[0].substring(2))/60);
        PushInfo pushInfo = new PushInfo(lng, lat, strings[4].substring(0,strings[4].indexOf(" IMSI")), strings[4].substring(strings[4].indexOf("IMSI: ") + 6), null,null);
        return  pushInfo;
    }

    public PushInfo analysis_help(String requestMsg){
        String strings[] = requestMsg.split(",");
        PushInfo pushInfo = new PushInfo(null, null, null, strings[0],strings[1],null);
        return pushInfo;
    }

    public JsonTf gps_tf(String lng, String lat){
        String str = HttpRequest.sendGet("http://api.gpsspg.com/convert/coord","from=0&to=2&oid=" + oid + "&key=" + key + "&latlng=" + lat + "," + lng);
        JSONObject jsonObject = JSON.parseObject(str);
        JsonTf jsonTf = JSON.toJavaObject(jsonObject,JsonTf.class);
        return jsonTf;
    }

}
